<?php
class Maktifitas extends CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    function get_pendapatan_lain($table, $master, $detail){
      $query = "
        SELECT B.*
        FROM {$table} AS A
        LEFT JOIN m_{$master} AS B ON A.id_{$master} = B.id_{$master}
        WHERE A.id_outlet = {$detail}
        ";
      return $this->global_models->get_query($query);
    }
    function get_user_auto($q){
      $q = strtolower($q);
      $query = "
        SELECT `A`.`id_pic_users`, `B`.`id_users`, `B`.`name`, `C`.`name` as privilege
FROM (`d_pic_users` as A)
LEFT JOIN `m_users` as B ON `A`.`id_users` = `B`.`id_users`
LEFT JOIN `d_user_privilege` as D ON `B`.`id_users` = `D`.`id_users`
LEFT JOIN `m_privilege` as C ON `D`.`id_privilege` = `C`.`id_privilege`
WHERE `A`.`id_outlet` =  '{$this->session->userdata('outlet')}'
AND  (LOWER(B.name)  LIKE '%{$q}%'
OR  LOWER(C.name)  LIKE '%{$q}%')
GROUP BY `A`.`id_users`
        ";
//print $query;
      $data = $this->db->query($query)->result();
      $items = array();
      if(is_array($data)){
        foreach($data as $dt){
          $items[$dt->name." | ".$dt->privilege] = $dt->id_pic_users;
        }
      }
      return $items;
    }
    function pica_xls($id){
      $detail = $this->global_models->get("m_actifity_report", array("id_actifity_report"  =>  $id));
      $parent = array(
        1 => "SDM",
        2 => "Jasa service  dan Part",
        3 => "Administrasi",
        4 => "Marketing dan Promo",
        5 => "Tools",
      );
      foreach ($parent as $ky => $prt){
        $data[$ky] = $this->global_models->get("d_history", array("id_actifity_report"  =>  $id, "kategori" => $ky));
      }
      
      $bulan = array(
          "1" =>  "Januari",
          "2" =>  "Februari",
          "3" =>  "Maret",
          "4" =>  "April",
          "5" =>  "Mei",
          "6" =>  "Juni",
          "7" =>  "Juli",
          "8" =>  "Agustus",
          "9" =>  "September",
          "10" =>  "Oktober",
          "11" =>  "Nopember",
          "12" =>  "Desember",
      );
      $outlet = $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet));
      $filename = "PICA-".$bulan[$detail[0]->month]."-".$detail[0]->year."-Outlet {$outlet}";
      $objPHPExcel = $this->phpexcel;
      $objPHPExcel->getProperties()->setCreator("Mr Montir")
							 ->setLastModifiedBy("Mr Montir")
							 ->setTitle("Users Data")
							 ->setSubject("Users Data")
							 ->setDescription("Report users data.")
							 ->setKeywords("report users data")
							 ->setCategory("Users");

      $objPHPExcel->setActiveSheetIndex(0);
      
      $objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', 'PICA');
      $objPHPExcel->getActiveSheet()->mergeCells('A2:F2');
      $objPHPExcel->getActiveSheet()->setCellValue('A2', '(Problem Identification & Corrective Action)');
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Outlet');
      $objPHPExcel->getActiveSheet()->setCellValue('C4', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Tanggal');
      $objPHPExcel->getActiveSheet()->setCellValue('C5', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->setCellValue('A6', 'Bulan');
      $objPHPExcel->getActiveSheet()->setCellValue('A7', 'Minggu ke');
      
      for($f = 4 ; $f <= 7 ; $f++){
        $objPHPExcel->getActiveSheet()->getStyle("C{$f}")->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
      }
      
      $objPHPExcel->getActiveSheet()->getStyle('A9:F9')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getRowDimension(9)->setRowHeight(30);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A9', 'No');
      $objPHPExcel->getActiveSheet()->getStyle("A9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->mergeCells('B9:C9');
      $objPHPExcel->getActiveSheet()->setCellValue('B9', 'Problem Identification');
      $objPHPExcel->getActiveSheet()->getStyle("B9:C9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('D9', 'Corrective Action');
      $objPHPExcel->getActiveSheet()->getStyle("D9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('E9', 'PIC');
      $objPHPExcel->getActiveSheet()->getStyle("E9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('F9', 'Due Date');
      $objPHPExcel->getActiveSheet()->getStyle("F9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      if(is_array($data)){
        $nok = 1;
        foreach($data as $key => $dt){
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok), $key);
          $objPHPExcel->getActiveSheet()->getStyle("A".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->setCellValue('B'.(9+$nok), $parent[$key]);
          
          $objPHPExcel->getActiveSheet()->getStyle("B".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                  'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
                ),
                'borders' => array(
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("C".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("D".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("E".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("F".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
//          $objPHPExcel->getActiveSheet()->mergeCells('B'.(9+$nok).':F'.(9+$nok));
          if(is_array($dt)){
            $nok += 1;
            foreach($dt as $kdt => $inti){
              $objPHPExcel->getActiveSheet()->getStyle("A".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                      'left'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('B'.(9+$nok), "*");
              $objPHPExcel->getActiveSheet()->getStyle("B".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                      'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('C'.(9+$nok), $inti->problem);
              $objPHPExcel->getActiveSheet()->getStyle("C".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok), $inti->corrective);
              $objPHPExcel->getActiveSheet()->getStyle("D".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('E'.(9+$nok), $inti->id_pic_users);
              $objPHPExcel->getActiveSheet()->getStyle("E".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('F'.(9+$nok), $inti->due_date);
              $objPHPExcel->getActiveSheet()->getStyle("F".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                      ),
                    ),
                  )
              );
              $nok++;
            }
          }
        }
      }
      
      $objPHPExcel->getActiveSheet()->getStyle("A9:F".(8+$nok))->applyFromArray(
        array(
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+5), "Jakarta                                        ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+5).':C'.(9+$nok+5));
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+6), "Dibuat Oleh,");
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+6).':C'.(9+$nok+6));
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok+6), "Mengetahui");
      $objPHPExcel->getActiveSheet()->mergeCells('D'.(9+$nok+6).':F'.(9+$nok+6));
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+11), "Bussines Consultant");
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+11).':C'.(9+$nok+11));
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok+11), "Kepala Outlet");
      
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(9+$nok+11), "Owner");
      $objPHPExcel->getActiveSheet()->mergeCells('E'.(9+$nok+11).':F'.(9+$nok+11));
      
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+6).':C'.(9+$nok+6))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+7).':C'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+7).':D'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('E'.(9+$nok+7).':F'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+11).':C'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+11).':D'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('E'.(9+$nok+11).':F'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+6).':F'.(9+$nok+6))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(4);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(7);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(35);
      $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(35);
      $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
      $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
      
      $objPHPExcel->getActiveSheet()->freezePane('A10');
      
      $objPHPExcel->setActiveSheetIndex(0);
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="'.$filename."-".date("Y m d").'"');
      header('Cache-Control: max-age=0');
      $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');
//$objWriter->save(str_replace('.php', '.xls', __FILE__));
      $objWriter->save('php://output');die;
      
    }
    function history_xls($id){
      $detail = $this->global_models->get("m_actifity_report", array("id_actifity_report"  =>  $id));
      $data = $this->global_models->get("d_pica", array("id_actifity_report"  =>  $id));
      
      $bulan = array(
          "1" =>  "Januari",
          "2" =>  "Februari",
          "3" =>  "Maret",
          "4" =>  "April",
          "5" =>  "Mei",
          "6" =>  "Juni",
          "7" =>  "Juli",
          "8" =>  "Agustus",
          "9" =>  "September",
          "10" =>  "Oktober",
          "11" =>  "Nopember",
          "12" =>  "Desember",
      );
      $outlet = $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet));
      $filename = "History-".$bulan[$detail[0]->month]."-".$detail[0]->year."-Outlet {$outlet}";
      $objPHPExcel = $this->phpexcel;
      $objPHPExcel->getProperties()->setCreator("Mr Montir")
							 ->setLastModifiedBy("Mr Montir")
							 ->setTitle("Users Data")
							 ->setSubject("Users Data")
							 ->setDescription("Report users data.")
							 ->setKeywords("report users data")
							 ->setCategory("Users");

      $objPHPExcel->setActiveSheetIndex(0);
      
      $objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', 'HISTORY');
      $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Outlet');
      $objPHPExcel->getActiveSheet()->getStyle('A3')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('B3', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Tanggal');
      $objPHPExcel->getActiveSheet()->getStyle('A4')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('B4', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Bulan');
      $objPHPExcel->getActiveSheet()->getStyle('A5')->getFont()->setBold(true);
      
      for($f = 3 ; $f <= 5 ; $f++){
        $objPHPExcel->getActiveSheet()->getStyle("B{$f}")->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Date');
      $objPHPExcel->getActiveSheet()->getStyle("A8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('B8', 'Problem Identification');
      $objPHPExcel->getActiveSheet()->getStyle("B8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('C8', 'Corrective Action');
      $objPHPExcel->getActiveSheet()->getStyle("C8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('D8', 'PIC');
      $objPHPExcel->getActiveSheet()->getStyle("D8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('E8', 'Due Date');
      $objPHPExcel->getActiveSheet()->getStyle("E8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A8:E8')->getFont()->setBold(true);
      
      if(is_array($data)){
        $no = 0;
        foreach ($data as $key => $value) {
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$no), $value->create_date);
          $objPHPExcel->getActiveSheet()->setCellValue('B'.(9+$no), $value->problem);
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(9+$no), $value->corrective);
          $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$no), $value->id_pic_users);
          $objPHPExcel->getActiveSheet()->setCellValue('E'.(9+$no), $value->due_date);
          $objPHPExcel->getActiveSheet()->getStyle("A".(9+$no))->applyFromArray(
            array(
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("B".(9+$no))->applyFromArray(
            array(
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("C".(9+$no))->applyFromArray(
            array(
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("D".(9+$no))->applyFromArray(
            array(
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("E".(9+$no))->applyFromArray(
            array(
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $no++;
        }
      }
      
      $objPHPExcel->getActiveSheet()->getStyle('B9:C'.(8+$no))->getAlignment()->setWrapText(true);
      
      $objPHPExcel->getActiveSheet()->getStyle("A9:E".(8+$no))->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(18);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(40);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40);
      $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
      $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
      
      $objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(30);
      
      $objPHPExcel->setActiveSheetIndex(0);
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="'.$filename."-".date("Y m d").'"');
      header('Cache-Control: max-age=0');
      $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');
//$objWriter->save(str_replace('.php', '.xls', __FILE__));
      $objWriter->save('php://output');die;
      
    }
    function page($id, $sht = 0){
      
      $detail = $this->global_models->get("m_actifity_report", array("id_actifity_report"  =>  $id));
      $target = $this->global_models->get("d_day_actifity_report", array("id_actifity_report"  =>  $id, "tanggal" => 0));
//      print '<pre>';
//      print_r($detail);die;
      
      $bulan = array(
          "1" =>  "Januari",
          "2" =>  "Februari",
          "3" =>  "Maret",
          "4" =>  "April",
          "5" =>  "Mei",
          "6" =>  "Juni",
          "7" =>  "Juli",
          "8" =>  "Agustus",
          "9" =>  "September",
          "10" =>  "Oktober",
          "11" =>  "Nopember",
          "12" =>  "Desember",
      );
      $outlet = $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet));
      $filename = "FS-".$bulan[$detail[0]->month]."-".$detail[0]->year."-Outlet {$outlet}";
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_opex AS B", "A.id_opex = B.id_opex","left");
      $opex = $this->db->get("d_opex_outlet AS A")->result();
      
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_pendapatan_lain AS B", "A.id_pendapatan_lain = B.id_pendapatan_lain","left");
      $pendapatan = $this->db->get("d_pendapatan_lain_outlet AS A")->result();
      
      
      $objPHPExcel = $this->phpexcel;
      $objPHPExcel->getProperties()->setCreator("Mr Montir")
							 ->setLastModifiedBy("Mr Montir")
							 ->setTitle("Users Data")
							 ->setSubject("Users Data")
							 ->setDescription("Report users data.")
							 ->setKeywords("report users data")
							 ->setCategory("Users");

      $objPHPExcel->setActiveSheetIndex($sht);
      
      $objPHPExcel->getActiveSheet()->mergeCells('A1:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', 'LAPORAN HARIAN OUTLET');
      $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->getStyle('A3:A5')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Outlet');
      $objPHPExcel->getActiveSheet()->setCellValue('B3', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->mergeCells('B3:C3');
      $objPHPExcel->getActiveSheet()->getStyle("B3:C3")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Bulan');
      $objPHPExcel->getActiveSheet()->setCellValue('B4', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B4:C4');
      $objPHPExcel->getActiveSheet()->getStyle("B4:C4")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Tahun');
      $objPHPExcel->getActiveSheet()->setCellValue('B5', $detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B5:C5');
      $objPHPExcel->getActiveSheet()->getStyle("B5:C5")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Keterangan');
      $objPHPExcel->getActiveSheet()->mergeCells('A8:B8');
      $objPHPExcel->getActiveSheet()->getStyle("A8:B8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('C8', 'Target');
      $objPHPExcel->getActiveSheet()->getStyle("C8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
        $str_col = ord("C");
        $col = $str_col + $day;
        $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col))->setWidth(14);
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."8", $day);
//        $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col))->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."8")->applyFromArray(
            array(
              'alignment' => array(
                'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
              ),
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $col_realisasi = $this->int_to_string(($col + 1));
      $int_col_realisasi = ($col + 1);
      
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 1)).'8', 'Realisasi');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 1))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 1))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 2)).'8', 'Target Per Hari');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 2))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 2))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 3)).'8', 'Achievement');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 3))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 3))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A9', 'UNIT ENTRY');
      $h = $this->int_to_string(65+5+$detail[0]->day_in_month);
      $objPHPExcel->getActiveSheet()->getStyle("A9:".$h."9")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A9')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A10', 'Servis Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A10:B10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C10', $target[0]->service);
      $objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C10:C10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $data_unit_entry = $this->global_models->get("d_day_actifity_report",array("id_actifity_report" => $id, "tanggal >" => 0));
      for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
        $str_col = ord("C");
        $col = $str_col + $day;
//        $data = $this->global_models->get("d_day_actifity_report",array("id_actifity_report" => $id, "tanggal" => $day));
        $entry = array();
        if(is_array($data_unit_entry)){
          foreach($data_unit_entry as $k_due => $due){
            if($due->tanggal == $day){
              $entry = array(
                  "service" => $due->service,
                  "service_belanja" => $due->service_belanja,
                  "belanja" => $due->belanja,
                  "p_service" => $due->p_service,
                  "p_service_plus" => $due->p_service_plus,
                  "p_belanja_plus" => $due->p_belanja_plus,
                  "p_belanja" => $due->p_belanja,
                  "total_hpp" => $due->total_hpp,
              );
              unset($data_unit_entry[$k_due]);
            }
          }
        }
//        print '<pre>';
//        print_r($data);die;
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."10", $entry['service']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."10")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."10")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."11", $entry['service_belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."11")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."11")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."12", $entry['belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."12")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."13", "=".$this->int_to_string($col)."10+".$this->int_to_string($col)."11");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."13")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."13")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."14", "=".$this->int_to_string($col)."12+".$this->int_to_string($col)."11");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."14")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."14")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."15", "=SUM(".$this->int_to_string($col)."10:".$this->int_to_string($col)."12)");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."15")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."15")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."19", $entry['p_service']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."19")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."19")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."20", $entry['p_service_plus']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."20")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."20")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."21", $entry['p_belanja_plus']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."21")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."21")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."22", $entry['p_belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."22")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."22")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."17", 
        '=IF(('.$this->int_to_string($col).'10+'.$this->int_to_string($col).'11) > 0,('.$this->int_to_string($col).'19 + '.$this->int_to_string($col).'20)/('.$this->int_to_string($col).'10+'.$this->int_to_string($col).'11),"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."17")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."17")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."18", 
                '=IF(('.$this->int_to_string($col).'12+'.$this->int_to_string($col).'11) > 0, ('.$this->int_to_string($col).'21 + '.$this->int_to_string($col).'22)/('.$this->int_to_string($col).'12+'.$this->int_to_string($col).'11), "")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."18")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."18")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."23", "=SUM(".$this->int_to_string($col)."19:".$this->int_to_string($col)."22)");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."23")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."23")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."24", 
                '=IF('.$this->int_to_string($col).'15 > 0, '.$this->int_to_string($col).'23/'.$this->int_to_string($col).'15,"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."24")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."24")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."27", $entry['total_hpp']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."27")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."27")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."26", 
        '=IF(('.$this->int_to_string($col).'21+'.$this->int_to_string($col).'22) > 0, '.$this->int_to_string($col).'27/('.$this->int_to_string($col).'21+'.$this->int_to_string($col).'22)*100,"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."26")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."26")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."28", "=".$this->int_to_string($col)."23-".$this->int_to_string($col)."27");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."28")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."28")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $col_realisasi_akhir = $this->int_to_string($int_col_realisasi - 1);
      $col_target = $this->int_to_string($int_col_realisasi + 1);
      $col_achi = $this->int_to_string($int_col_realisasi + 2);
//      print $col_realisasi_akhir."<br>";
//      print $col_target."<br>";
//      print $col_realisasi;die;
      $total_akhirnya = 34 + count($opex) + count($pendapatan);
      for($loop_real = 10 ; $loop_real <= $total_akhirnya ; $loop_real++){
        $spesial_hpp = "";
        if($loop_real == 17 OR $loop_real == 18){
          $normal = '=AVERAGE(D'.$loop_real.':'.$col_realisasi_akhir.$loop_real.')';
          if($loop_real == 17)
            $target_perhari = $target[0]->rata_service;
          if($loop_real == 18)
            $target_perhari = $target[0]->rata_belanja;
        }
        else if($loop_real == 26){
          $normal = '=IF(('.$col_realisasi.'21+'.$col_realisasi.'22)>0,'.$col_realisasi.'27/('.$col_realisasi.'21+'.$col_realisasi.'22)*100,"")';
          $target_perhari = $target[0]->hpp;
          $spesial_hpp = "/100";
        }
        else{
          $normal = '=SUM(D'.$loop_real.':'.$col_realisasi_akhir.$loop_real.')';
          $target_perhari = '=1/'.$detail[0]->day_in_month.'*C'.$loop_real;
        }
        $objPHPExcel->getActiveSheet()->setCellValue($col_realisasi.$loop_real, $normal);
        $objPHPExcel->getActiveSheet()->getStyle($col_realisasi.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($col_realisasi.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($col_target.$loop_real, $target_perhari);
        $objPHPExcel->getActiveSheet()->getStyle($col_target.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($col_target.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($col_achi.$loop_real, '=IF(C'.$loop_real.' > 0,'.$col_realisasi.$loop_real."/C".$loop_real.$spesial_hpp.', "")');
        $objPHPExcel->getActiveSheet()->getStyle($col_achi.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
        $objPHPExcel->getActiveSheet()->getStyle($col_achi.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A11', 'Servis + Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A11:B11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C11', $target[0]->service_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C11:C11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A12', 'Belanja Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A12:B12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C12', $target[0]->belanja);
      $objPHPExcel->getActiveSheet()->getStyle("C12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C12:C12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A13', 'Total Unit Entry Service');
      $objPHPExcel->getActiveSheet()->getStyle("A13:B13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C13', "=C10+C11");
      $objPHPExcel->getActiveSheet()->getStyle('C13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C13:C13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A14', 'Total Unit Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A14:B14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C14', "=C11+C12");
      $objPHPExcel->getActiveSheet()->getStyle('C14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C14:C14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A15', 'Total Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A15:B15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_total_transaksi = $target[0]->service + $target[0]->service_belanja + $target[0]->belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C15', "=SUM(C10:C12)");
      $objPHPExcel->getActiveSheet()->getStyle('C15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C15:C15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A16', 'PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A16:".$h."16")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A17', 'Rata-rata Rupiah Service');
      $objPHPExcel->getActiveSheet()->getStyle("A17:B17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C17', $target[0]->rata_service);
      $objPHPExcel->getActiveSheet()->getStyle('C17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C17:C17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A18', 'Rata-rata Rupiah Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A18:B18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C18', $target[0]->rata_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('C18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C18:C18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A13:A18')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A19', 'Service Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A19:B19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_service = $target[0]->rata_service * $target[0]->service;
      $objPHPExcel->getActiveSheet()->setCellValue('C19', "=C17*C10");
      $objPHPExcel->getActiveSheet()->getStyle('C19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C19:C19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A20', 'Service + Belanja');
      $objPHPExcel->getActiveSheet()->setCellValue('B20', 'Service');
      $objPHPExcel->getActiveSheet()->getStyle("A20:B20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_service_p = $target[0]->rata_service * $target[0]->service_belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C20', "=C17*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C20:C20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('B21', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A21:B21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_belanja_p = $target[0]->rata_belanja * $target[0]->service_belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C21', "=C18*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C21:C21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A22', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A22:B22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_belanja = $target[0]->rata_belanja * $target[0]->belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C22', "=C18*C12");
      $objPHPExcel->getActiveSheet()->getStyle('C22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C22:C22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A23', 'Total PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A23:B23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_penerimaan = $target_rp_belanja + $target_rp_belanja_p + $target_rp_service + $target_rp_service_p;
      $objPHPExcel->getActiveSheet()->setCellValue('C23', "=SUM(C19:C22)");
      $objPHPExcel->getActiveSheet()->getStyle('C23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C23:C23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A24', 'Omset per Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A24:B24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_rp_omset = $target_rp_penerimaan/ $target_total_transaksi;
      $objPHPExcel->getActiveSheet()->setCellValue('C24', '=IF(C15 > 0, C23/C15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('C24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C24:C24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A24')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A25', 'HARGA POKOK PEMBELIAN');
      $objPHPExcel->getActiveSheet()->getStyle("A25:".$h."25")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A25')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('B26', '% HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A26:B26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C26', $target[0]->hpp/100);
      $objPHPExcel->getActiveSheet()->getStyle('C26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("C26:C26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A27', 'Total HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A27:B27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_total_hpp = $target[0]->hpp * ($target_rp_belanja + $target_rp_belanja_p) / 100;
      $objPHPExcel->getActiveSheet()->setCellValue('C27', "=C26*(C22+C21)");
      $objPHPExcel->getActiveSheet()->getStyle('C27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C27:C27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A28', 'GROSS MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A28:B28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_gross_margin = $target_rp_penerimaan - $target_total_hpp;
      $objPHPExcel->getActiveSheet()->setCellValue('C28', "=C23-C27");
      $objPHPExcel->getActiveSheet()->getStyle('C28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C28:C28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A29', 'OPERATIONAL EXPENSE (OPEX)');
      $objPHPExcel->getActiveSheet()->getStyle("A29:".$h."29")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A27:A29')->getFont()->setBold(true);
      
      if(is_array($opex)){
        $no = 1;
        $target_opex_total = "=SUM(C".(29+$no);
        $str_col = ord("C");
        $cell_awal = (29+1);
        foreach($opex as $op){
          $data_opex = $this->global_models->get("d_day_actifity_opex",array("id_actifity_report" => $id, "tanggal >" => 0, "id_opex" => $op->id_opex));
          for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
            $opex_qty = "";
            $col = $str_col + $day;
            $data = $this->global_models->get("d_day_actifity_opex",array("id_actifity_report" => $id, "tanggal" => $day, "id_opex" => $op->id_opex));
            
            if(is_array($data_opex)){
              foreach($data_opex as $k_do => $do){
                if($do->tanggal == $day){
                  $opex_qty = $do->qty;
                  unset($data_opex[$k_do]);
                }
              }
            }
            
            $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(29+$no), $opex_qty);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->applyFromArray(
                array(
                  'borders' => array(
                    'left'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'right'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'top'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'bottom'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                  ),
                )
            );
            
          }
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_opex = $this->global_models->get_field("d_day_actifity_opex", "qty", array("id_actifity_report" => $id, "id_opex" => $op->id_opex, "tanggal" => 0));
          if($target_opex === FALSE)
            $target_opex = "";
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $no++;
        }
        for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
          $col = $str_col + $day;
          
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(29+$no), "=SUM(".$this->int_to_string($col).$cell_awal.":".$this->int_to_string($col).(28+$no).")");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $angka_margin = (30+$no);
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(30+$no), "=".$this->int_to_string($col)."28-".$this->int_to_string($col).(29+$no)."");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(30+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );

        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), 'Total Opex');
      $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print $target_opex_total.":C".(29+$no).")";die;
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex_total.":C".(28+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(30+$no), 'MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A".(30+$no).":B".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_margin = $target_gross_margin - $target_opex_total;
      $kl = 'C'.(30+$no);
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(30+$no), "=C28-C".(29+$no));
      $objPHPExcel->getActiveSheet()->getStyle('C'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(30+$no).":C".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print_r($opex);die;
      
      $objPHPExcel->getActiveSheet()->getStyle('A'.(29+$no).':A'.(30+$no))->getFont()->setBold(true);
      $no = 30+$no;
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(1+$no), 'PENDAPATAN LAIN-LAIN');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(1+$no))->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle("A".(1+$no).":".$h.(1+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      if(is_array($pendapatan)){
        $target_pendapatan_total = "=SUM(C".(2+$no);
        $str_col = ord("C");
        $cell_awal_row = ($no+2);
        foreach($pendapatan as $op){
          $pendapatan_qty = "";
          $data_pendapatan = $this->global_models->get("d_day_actifity_pendapatan_lain",array("id_actifity_report" => $id, "tanggal" => $day, "id_pendapatan_lain" => $op->id_pendapatan_lain));
          
          for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
            $col = $str_col + $day;
            if(is_array($data_pendapatan)){
              foreach($data_pendapatan as $k_dp => $dp){
                if($dp->tanggal == $day){
                  $pendapatan_qty = $dp->qty;
                  unset($data_pendapatan[$k_dp]);
                }
              }
            }
            
            $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(2+$no), $pendapatan_qty);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->applyFromArray(
                array(
                  'borders' => array(
                    'left'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'right'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'top'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'bottom'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                  ),
                )
            );
            
          }
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_pendapatan = $this->global_models->get_field("d_day_actifity_pendapatan_lain", "qty", array("id_actifity_report" => $id, "id_pendapatan_lain" => $op->id_pendapatan_lain, "tanggal" => 0));
          if($target_pendapatan === FALSE)
            $target_pendapatan = "";
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $no++;
        }
        for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
          $col = $str_col + $day;
          
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(2+$no), "=SUM(".$this->int_to_string($col).$cell_awal_row.":".$this->int_to_string($col).(1+$no).")");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(3+$no), "=".$this->int_to_string($col).$angka_margin."-".$this->int_to_string($col).(2+$no)."");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(3+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );

        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), 'Total Pendapatan Lain');
      $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan_total.":C".(1+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(3+$no), 'LABA/RUGI');
      $objPHPExcel->getActiveSheet()->getStyle("A".(3+$no).":B".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A7', '* Tekan F2 lalu Enter untuk format angka exponential');
      $objPHPExcel->getActiveSheet()->getStyle('A7')->getFont()->setItalic(true);
      $objPHPExcel->getActiveSheet()->getStyle("A7")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
//      $target_laba = $target_pendapatan_total + $target_margin;
//      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+9");
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+".$kl);
      $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(3+$no).":C".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->freezePane('D9');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(2+$no).':A'.(3+$no))->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->getStyle('A8:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'8')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(17);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(14);
      
      $objPHPExcel->getActiveSheet()->setTitle('Laporan Harian Outlet'."-".$detail[0]->month."-".$detail[0]->year);
      
      $objPHPExcel->createSheet();
      
       $parent = array(
        1 => "SDM",
        2 => "Jasa service  dan Part",
        3 => "Administrasi",
        4 => "Marketing dan Promo",
        5 => "Tools",
      );
      foreach ($parent as $ky => $prt){
        $data[$ky] = $this->global_models->get("d_history", array("id_actifity_report"  =>  $id, "kategori" => $ky));
      }
      

      $objPHPExcel->setActiveSheetIndex($sht+1);
      
    //  return $objPHPExcel;
    }
   
    function fs_export_xls1($id,$outlet){
      //$ids = array(0 => 240, 1 => 269);
      
      foreach ($id as $kk => $value) {
        $objPHPExcel = $this->page($value, $kk);
      }
      
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="'."LAPORAN OUTLET"." ".$outlet."-".date("Y m d").'"');
      header('Cache-Control: max-age=0');
      $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');
//$objWriter->save(str_replace('.php', '.xls', __FILE__));
      $objWriter->save('php://output');  
//      die;
      
    }
    function fs_export_xls($id){
      $detail = $this->global_models->get("m_actifity_report", array("id_actifity_report"  =>  $id));
      $target = $this->global_models->get("d_day_actifity_report", array("id_actifity_report"  =>  $id, "tanggal" => 0));
//      print '<pre>';
//      print_r($detail);die;
      
      $bulan = array(
          "1" =>  "Januari",
          "2" =>  "Februari",
          "3" =>  "Maret",
          "4" =>  "April",
          "5" =>  "Mei",
          "6" =>  "Juni",
          "7" =>  "Juli",
          "8" =>  "Agustus",
          "9" =>  "September",
          "10" =>  "Oktober",
          "11" =>  "Nopember",
          "12" =>  "Desember",
      );
      $outlet = $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet));
      $filename = "FS-".$bulan[$detail[0]->month]."-".$detail[0]->year."-Outlet {$outlet}";
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_opex AS B", "A.id_opex = B.id_opex","left");
      $opex = $this->db->get("d_opex_outlet AS A")->result();
      
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_pendapatan_lain AS B", "A.id_pendapatan_lain = B.id_pendapatan_lain","left");
      $pendapatan = $this->db->get("d_pendapatan_lain_outlet AS A")->result();
      
      
      $objPHPExcel = $this->phpexcel;
      $objPHPExcel->getProperties()->setCreator("Mr Montir")
							 ->setLastModifiedBy("Mr Montir")
							 ->setTitle("Users Data")
							 ->setSubject("Users Data")
							 ->setDescription("Report users data.")
							 ->setKeywords("report users data")
							 ->setCategory("Users");

      $objPHPExcel->setActiveSheetIndex(0);
      
      $objPHPExcel->getActiveSheet()->mergeCells('A1:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', 'LAPORAN HARIAN OUTLET');
      $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->getStyle('A3:A5')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Outlet');
      $objPHPExcel->getActiveSheet()->setCellValue('B3', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->mergeCells('B3:C3');
      $objPHPExcel->getActiveSheet()->getStyle("B3:C3")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Bulan');
      $objPHPExcel->getActiveSheet()->setCellValue('B4', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B4:C4');
      $objPHPExcel->getActiveSheet()->getStyle("B4:C4")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Tahun');
      $objPHPExcel->getActiveSheet()->setCellValue('B5', $detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B5:C5');
      $objPHPExcel->getActiveSheet()->getStyle("B5:C5")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Keterangan');
      $objPHPExcel->getActiveSheet()->mergeCells('A8:B8');
      $objPHPExcel->getActiveSheet()->getStyle("A8:B8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('C8', 'Target');
      $objPHPExcel->getActiveSheet()->getStyle("C8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
        $str_col = ord("C");
        $col = $str_col + $day;
        $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col))->setWidth(14);
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."8", $day);
//        $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col))->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."8")->applyFromArray(
            array(
              'alignment' => array(
                'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
                'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
              ),
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $col_realisasi = $this->int_to_string(($col + 1));
      $int_col_realisasi = ($col + 1);
      
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 1)).'8', 'Realisasi');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 1))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 1))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 2)).'8', 'Target Per Hari');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 2))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 2))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string(($col + 3)).'8', 'Achievement');
      $objPHPExcel->getActiveSheet()->getColumnDimension($this->int_to_string($col + 3))->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string(($col + 3))."8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A9', 'UNIT ENTRY');
      $h = $this->int_to_string(65+5+$detail[0]->day_in_month);
      $objPHPExcel->getActiveSheet()->getStyle("A9:".$h."9")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A9')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A10', 'Servis Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A10:B10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C10', $target[0]->service);
      $objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C10:C10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $data_unit_entry = $this->global_models->get("d_day_actifity_report",array("id_actifity_report" => $id, "tanggal >" => 0));
      for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
        $str_col = ord("C");
        $col = $str_col + $day;
//        $data = $this->global_models->get("d_day_actifity_report",array("id_actifity_report" => $id, "tanggal" => $day));
        $entry = array();
        if(is_array($data_unit_entry)){
          foreach($data_unit_entry as $k_due => $due){
            if($due->tanggal == $day){
              $entry = array(
                  "service" => $due->service,
                  "service_belanja" => $due->service_belanja,
                  "belanja" => $due->belanja,
                  "p_service" => $due->p_service,
                  "p_service_plus" => $due->p_service_plus,
                  "p_belanja_plus" => $due->p_belanja_plus,
                  "p_belanja" => $due->p_belanja,
                  "total_hpp" => $due->total_hpp,
              );
              unset($data_unit_entry[$k_due]);
            }
          }
        }
//        print '<pre>';
//        print_r($data);die;
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."10", $entry['service']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."10")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."10")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."11", $entry['service_belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."11")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."11")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."12", $entry['belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."12")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."13", "=".$this->int_to_string($col)."10+".$this->int_to_string($col)."11");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."13")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."13")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."14", "=".$this->int_to_string($col)."12+".$this->int_to_string($col)."11");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."14")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."14")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."15", "=SUM(".$this->int_to_string($col)."10:".$this->int_to_string($col)."12)");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."15")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."15")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."19", $entry['p_service']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."19")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."19")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."20", $entry['p_service_plus']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."20")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."20")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."21", $entry['p_belanja_plus']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."21")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."21")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."22", $entry['p_belanja']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."22")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."22")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."17", 
        '=IF(('.$this->int_to_string($col).'10+'.$this->int_to_string($col).'11) > 0,('.$this->int_to_string($col).'19 + '.$this->int_to_string($col).'20)/('.$this->int_to_string($col).'10+'.$this->int_to_string($col).'11),"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."17")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."17")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."18", 
                '=IF(('.$this->int_to_string($col).'12+'.$this->int_to_string($col).'11) > 0, ('.$this->int_to_string($col).'21 + '.$this->int_to_string($col).'22)/('.$this->int_to_string($col).'12+'.$this->int_to_string($col).'11), "")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."18")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."18")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."23", "=SUM(".$this->int_to_string($col)."19:".$this->int_to_string($col)."22)");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."23")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."23")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."24", 
                '=IF('.$this->int_to_string($col).'15 > 0, '.$this->int_to_string($col).'23/'.$this->int_to_string($col).'15,"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."24")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."24")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."27", $entry['total_hpp']);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."27")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."27")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."26", 
        '=IF(('.$this->int_to_string($col).'21+'.$this->int_to_string($col).'22) > 0, '.$this->int_to_string($col).'27/('.$this->int_to_string($col).'21+'.$this->int_to_string($col).'22)*100,"")');
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."26")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."26")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col)."28", "=".$this->int_to_string($col)."23-".$this->int_to_string($col)."27");
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."28")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col)."28")->applyFromArray(
            array(
              'borders' => array(
                'left'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'top'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $col_realisasi_akhir = $this->int_to_string($int_col_realisasi - 1);
      $col_target = $this->int_to_string($int_col_realisasi + 1);
      $col_achi = $this->int_to_string($int_col_realisasi + 2);
//      print $col_realisasi_akhir."<br>";
//      print $col_target."<br>";
//      print $col_realisasi;die;
      $total_akhirnya = 34 + count($opex) + count($pendapatan);
      for($loop_real = 10 ; $loop_real <= $total_akhirnya ; $loop_real++){
        $spesial_hpp = "";
        if($loop_real == 17 OR $loop_real == 18){
          $normal = '=AVERAGE(D'.$loop_real.':'.$col_realisasi_akhir.$loop_real.')';
          if($loop_real == 17)
            $target_perhari = $target[0]->rata_service;
          if($loop_real == 18)
            $target_perhari = $target[0]->rata_belanja;
        }
        else if($loop_real == 26){
          $normal = '=IF(('.$col_realisasi.'21+'.$col_realisasi.'22)>0,'.$col_realisasi.'27/('.$col_realisasi.'21+'.$col_realisasi.'22)*100,"")';
          $target_perhari = $target[0]->hpp;
          $spesial_hpp = "/100";
        }
        else{
          $normal = '=SUM(D'.$loop_real.':'.$col_realisasi_akhir.$loop_real.')';
          $target_perhari = '=1/'.$detail[0]->day_in_month.'*C'.$loop_real;
        }
        $objPHPExcel->getActiveSheet()->setCellValue($col_realisasi.$loop_real, $normal);
        $objPHPExcel->getActiveSheet()->getStyle($col_realisasi.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($col_realisasi.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($col_target.$loop_real, $target_perhari);
        $objPHPExcel->getActiveSheet()->getStyle($col_target.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
        $objPHPExcel->getActiveSheet()->getStyle($col_target.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
        
        $objPHPExcel->getActiveSheet()->setCellValue($col_achi.$loop_real, '=IF(C'.$loop_real.' > 0,'.$col_realisasi.$loop_real."/C".$loop_real.$spesial_hpp.', "")');
        $objPHPExcel->getActiveSheet()->getStyle($col_achi.$loop_real)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
        $objPHPExcel->getActiveSheet()->getStyle($col_achi.$loop_real)->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
                'right'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                ),
              ),
            )
        );
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A11', 'Servis + Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A11:B11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C11', $target[0]->service_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C11:C11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A12', 'Belanja Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A12:B12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C12', $target[0]->belanja);
      $objPHPExcel->getActiveSheet()->getStyle("C12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C12:C12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A13', 'Total Unit Entry Service');
      $objPHPExcel->getActiveSheet()->getStyle("A13:B13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C13', "=C10+C11");
      $objPHPExcel->getActiveSheet()->getStyle('C13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C13:C13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A14', 'Total Unit Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A14:B14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C14', "=C11+C12");
      $objPHPExcel->getActiveSheet()->getStyle('C14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C14:C14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A15', 'Total Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A15:B15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_total_transaksi = $target[0]->service + $target[0]->service_belanja + $target[0]->belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C15', "=SUM(C10:C12)");
      $objPHPExcel->getActiveSheet()->getStyle('C15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C15:C15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A16', 'PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A16:".$h."16")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A17', 'Rata-rata Rupiah Service');
      $objPHPExcel->getActiveSheet()->getStyle("A17:B17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C17', $target[0]->rata_service);
      $objPHPExcel->getActiveSheet()->getStyle('C17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C17:C17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A18', 'Rata-rata Rupiah Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A18:B18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C18', $target[0]->rata_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('C18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C18:C18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A13:A18')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A19', 'Service Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A19:B19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_service = $target[0]->rata_service * $target[0]->service;
      $objPHPExcel->getActiveSheet()->setCellValue('C19', "=C17*C10");
      $objPHPExcel->getActiveSheet()->getStyle('C19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C19:C19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A20', 'Service + Belanja');
      $objPHPExcel->getActiveSheet()->setCellValue('B20', 'Service');
      $objPHPExcel->getActiveSheet()->getStyle("A20:B20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_service_p = $target[0]->rata_service * $target[0]->service_belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C20', "=C17*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C20:C20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('B21', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A21:B21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_belanja_p = $target[0]->rata_belanja * $target[0]->service_belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C21', "=C18*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C21:C21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A22', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A22:B22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_belanja = $target[0]->rata_belanja * $target[0]->belanja;
      $objPHPExcel->getActiveSheet()->setCellValue('C22', "=C18*C12");
      $objPHPExcel->getActiveSheet()->getStyle('C22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C22:C22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A23', 'Total PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A23:B23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_rp_penerimaan = $target_rp_belanja + $target_rp_belanja_p + $target_rp_service + $target_rp_service_p;
      $objPHPExcel->getActiveSheet()->setCellValue('C23', "=SUM(C19:C22)");
      $objPHPExcel->getActiveSheet()->getStyle('C23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C23:C23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A24', 'Omset per Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A24:B24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_rp_omset = $target_rp_penerimaan/ $target_total_transaksi;
      $objPHPExcel->getActiveSheet()->setCellValue('C24', '=IF(C15 > 0, C23/C15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('C24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C24:C24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A24')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A25', 'HARGA POKOK PEMBELIAN');
      $objPHPExcel->getActiveSheet()->getStyle("A25:".$h."25")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A25')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('B26', '% HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A26:B26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C26', $target[0]->hpp/100);
      $objPHPExcel->getActiveSheet()->getStyle('C26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("C26:C26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A27', 'Total HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A27:B27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_total_hpp = $target[0]->hpp * ($target_rp_belanja + $target_rp_belanja_p) / 100;
      $objPHPExcel->getActiveSheet()->setCellValue('C27', "=C26*(C22+C21)");
      $objPHPExcel->getActiveSheet()->getStyle('C27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C27:C27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A28', 'GROSS MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A28:B28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_gross_margin = $target_rp_penerimaan - $target_total_hpp;
      $objPHPExcel->getActiveSheet()->setCellValue('C28', "=C23-C27");
      $objPHPExcel->getActiveSheet()->getStyle('C28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C28:C28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A29', 'OPERATIONAL EXPENSE (OPEX)');
      $objPHPExcel->getActiveSheet()->getStyle("A29:".$h."29")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A27:A29')->getFont()->setBold(true);
      
      if(is_array($opex)){
        $no = 1;
        $target_opex_total = "=SUM(C".(29+$no);
        $str_col = ord("C");
        $cell_awal = (29+1);
        foreach($opex as $op){
          $data_opex = $this->global_models->get("d_day_actifity_opex",array("id_actifity_report" => $id, "tanggal >" => 0, "id_opex" => $op->id_opex));
          for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
            $opex_qty = "";
            $col = $str_col + $day;
            $data = $this->global_models->get("d_day_actifity_opex",array("id_actifity_report" => $id, "tanggal" => $day, "id_opex" => $op->id_opex));
            
            if(is_array($data_opex)){
              foreach($data_opex as $k_do => $do){
                if($do->tanggal == $day){
                  $opex_qty = $do->qty;
                  unset($data_opex[$k_do]);
                }
              }
            }
            
            $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(29+$no), $opex_qty);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->applyFromArray(
                array(
                  'borders' => array(
                    'left'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'right'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'top'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'bottom'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                  ),
                )
            );
            
          }
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_opex = $this->global_models->get_field("d_day_actifity_opex", "qty", array("id_actifity_report" => $id, "id_opex" => $op->id_opex, "tanggal" => 0));
          if($target_opex === FALSE)
            $target_opex = "";
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $no++;
        }
        for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
          $col = $str_col + $day;
          
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(29+$no), "=SUM(".$this->int_to_string($col).$cell_awal.":".$this->int_to_string($col).(28+$no).")");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $angka_margin = (30+$no);
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(30+$no), "=".$this->int_to_string($col)."28-".$this->int_to_string($col).(29+$no)."");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(30+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );

        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), 'Total Opex');
      $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print $target_opex_total.":C".(29+$no).")";die;
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex_total.":C".(28+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(30+$no), 'MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A".(30+$no).":B".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $target_margin = $target_gross_margin - $target_opex_total;
      $kl = 'C'.(30+$no);
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(30+$no), "=C28-C".(29+$no));
      $objPHPExcel->getActiveSheet()->getStyle('C'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(30+$no).":C".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print_r($opex);die;
      
      $objPHPExcel->getActiveSheet()->getStyle('A'.(29+$no).':A'.(30+$no))->getFont()->setBold(true);
      $no = 30+$no;
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(1+$no), 'PENDAPATAN LAIN-LAIN');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(1+$no))->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle("A".(1+$no).":".$h.(1+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      if(is_array($pendapatan)){
        $target_pendapatan_total = "=SUM(C".(2+$no);
        $str_col = ord("C");
        $cell_awal_row = ($no+2);
        foreach($pendapatan as $op){
          $pendapatan_qty = "";
          $data_pendapatan = $this->global_models->get("d_day_actifity_pendapatan_lain",array("id_actifity_report" => $id, "tanggal" => $day, "id_pendapatan_lain" => $op->id_pendapatan_lain));
          
          for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
            $col = $str_col + $day;
            if(is_array($data_pendapatan)){
              foreach($data_pendapatan as $k_dp => $dp){
                if($dp->tanggal == $day){
                  $pendapatan_qty = $dp->qty;
                  unset($data_pendapatan[$k_dp]);
                }
              }
            }
            
            $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(2+$no), $pendapatan_qty);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
            $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->applyFromArray(
                array(
                  'borders' => array(
                    'left'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'right'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'top'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                    'bottom'     => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                    ),
                  ),
                )
            );
            
          }
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_pendapatan = $this->global_models->get_field("d_day_actifity_pendapatan_lain", "qty", array("id_actifity_report" => $id, "id_pendapatan_lain" => $op->id_pendapatan_lain, "tanggal" => 0));
          if($target_pendapatan === FALSE)
            $target_pendapatan = "";
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $no++;
        }
        for($day = 1 ; $day <= $detail[0]->day_in_month ; $day++){
          $col = $str_col + $day;
          
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(2+$no), "=SUM(".$this->int_to_string($col).$cell_awal_row.":".$this->int_to_string($col).(1+$no).")");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->setCellValue($this->int_to_string($col).(3+$no), "=".$this->int_to_string($col).$angka_margin."-".$this->int_to_string($col).(2+$no)."");
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle($this->int_to_string($col).(3+$no))->applyFromArray(
              array(
                'borders' => array(
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );

        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), 'Total Pendapatan Lain');
      $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan_total.":C".(1+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(3+$no), 'LABA/RUGI');
      $objPHPExcel->getActiveSheet()->getStyle("A".(3+$no).":B".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A7', '* Tekan F2 lalu Enter untuk format angka exponential');
      $objPHPExcel->getActiveSheet()->getStyle('A7')->getFont()->setItalic(true);
      $objPHPExcel->getActiveSheet()->getStyle("A7")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
//      $target_laba = $target_pendapatan_total + $target_margin;
//      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+9");
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+".$kl);
      $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(3+$no).":C".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->freezePane('D9');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(2+$no).':A'.(3+$no))->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->getStyle('A8:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'8')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(17);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(14);
      
      $objPHPExcel->getActiveSheet()->setTitle('Laporan Harian Outlet');
      
      $objPHPExcel->createSheet();
      
       $parent = array(
        1 => "SDM",
        2 => "Jasa service  dan Part",
        3 => "Administrasi",
        4 => "Marketing dan Promo",
        5 => "Tools",
      );
      foreach ($parent as $ky => $prt){
        $data[$ky] = $this->global_models->get("d_history", array("id_actifity_report"  =>  $id, "kategori" => $ky));
      }
      

      $objPHPExcel->setActiveSheetIndex(1);
      
      $objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', 'PICA');
      $objPHPExcel->getActiveSheet()->mergeCells('A2:F2');
      $objPHPExcel->getActiveSheet()->setCellValue('A2', '(Problem Identification & Corrective Action)');
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel->getActiveSheet()->getStyle('A1:F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Outlet');
      $objPHPExcel->getActiveSheet()->setCellValue('C4', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Tanggal');
      $objPHPExcel->getActiveSheet()->setCellValue('C5', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->setCellValue('A6', 'Bulan');
      $objPHPExcel->getActiveSheet()->setCellValue('A7', 'Minggu ke');
      
      for($f = 4 ; $f <= 7 ; $f++){
        $objPHPExcel->getActiveSheet()->getStyle("C{$f}")->applyFromArray(
            array(
              'borders' => array(
                'bottom'     => array(
                  'style' => PHPExcel_Style_Border::BORDER_THIN
                ),
              ),
            )
        );
      }
      
      $objPHPExcel->getActiveSheet()->getStyle('A9:F9')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getRowDimension(9)->setRowHeight(30);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A9', 'No');
      $objPHPExcel->getActiveSheet()->getStyle("A9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->mergeCells('B9:C9');
      $objPHPExcel->getActiveSheet()->setCellValue('B9', 'Problem Identification');
      $objPHPExcel->getActiveSheet()->getStyle("B9:C9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('D9', 'Corrective Action');
      $objPHPExcel->getActiveSheet()->getStyle("D9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('E9', 'PIC');
      $objPHPExcel->getActiveSheet()->getStyle("E9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('F9', 'Due Date');
      $objPHPExcel->getActiveSheet()->getStyle("F9")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      if(is_array($data)){
        $nok = 1;
        foreach($data as $key => $dt){
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok), $key);
          $objPHPExcel->getActiveSheet()->getStyle("A".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'left'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->setCellValue('B'.(9+$nok), $parent[$key]);
          
          $objPHPExcel->getActiveSheet()->getStyle("B".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                  'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
                ),
                'borders' => array(
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("C".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("D".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("E".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          $objPHPExcel->getActiveSheet()->getStyle("F".(9+$nok))->applyFromArray(
            array(
                'alignment' => array(
                  'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                ),
                'borders' => array(
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                  'top'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
//          $objPHPExcel->getActiveSheet()->mergeCells('B'.(9+$nok).':F'.(9+$nok));
          if(is_array($dt)){
            $nok += 1;
            foreach($dt as $kdt => $inti){
              $objPHPExcel->getActiveSheet()->getStyle("A".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                      'left'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('B'.(9+$nok), "*");
              $objPHPExcel->getActiveSheet()->getStyle("B".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                      'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('C'.(9+$nok), $inti->problem);
              $objPHPExcel->getActiveSheet()->getStyle("C".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok), $inti->corrective);
              $objPHPExcel->getActiveSheet()->getStyle("D".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('E'.(9+$nok), $inti->id_pic_users);
              $objPHPExcel->getActiveSheet()->getStyle("E".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                      ),
                    ),
                  )
              );
              $objPHPExcel->getActiveSheet()->setCellValue('F'.(9+$nok), $inti->due_date);
              $objPHPExcel->getActiveSheet()->getStyle("F".(9+$nok))->applyFromArray(
                array(
                    'alignment' => array(
                      'vertical' => PHPExcel_Style_Alignment::VERTICAL_TOP,
                    ),
                    'borders' => array(
                      'right'     => array(
                        'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                      ),
                    ),
                  )
              );
              $nok++;
            }
          }
        }
      }
      
      $objPHPExcel->getActiveSheet()->getStyle("A9:F".(8+$nok))->applyFromArray(
        array(
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+5), "Jakarta                                        ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+5).':C'.(9+$nok+5));
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+6), "Dibuat Oleh,");
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+6).':C'.(9+$nok+6));
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok+6), "Mengetahui");
      $objPHPExcel->getActiveSheet()->mergeCells('D'.(9+$nok+6).':F'.(9+$nok+6));
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(9+$nok+11), "Bussines Consultant");
      $objPHPExcel->getActiveSheet()->mergeCells('A'.(9+$nok+11).':C'.(9+$nok+11));
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(9+$nok+11), "Kepala Outlet");
      
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(9+$nok+11), "Owner");
      $objPHPExcel->getActiveSheet()->mergeCells('E'.(9+$nok+11).':F'.(9+$nok+11));
      
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+6).':C'.(9+$nok+6))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+7).':C'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+7).':D'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('E'.(9+$nok+7).':F'.(9+$nok+10))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A'.(9+$nok+11).':C'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+11).':D'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('E'.(9+$nok+11).':F'.(9+$nok+11))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('D'.(9+$nok+6).':F'.(9+$nok+6))->applyFromArray(
        array(
            'alignment' => array(
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(4);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(7);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(35);
      $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(35);
      $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
      $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
      
      $objPHPExcel->getActiveSheet()->freezePane('A10');
      $objPHPExcel->getActiveSheet()->setTitle('PICA');
      $objPHPExcel->setActiveSheetIndex(0);
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="'.$filename."-".date("Y m d").'"');
      header('Cache-Control: max-age=0');
      $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');
//$objWriter->save(str_replace('.php', '.xls', __FILE__));
      $objWriter->save('php://output');die;
      
    }
    function int_to_string($int){
      if($int > 90){
        $selisih = $int % 90;
        $get = $int - $selisih;
        $pembagi = $get/90;
        $int_prem = $pembagi + 64;
        $string = chr($int_prem).chr($selisih + 64);
//        $int_temp = 
      }
      else{
        $string = chr($int);
      }
      return $string;
    }
    
    function get_privilege(){
      /**
     * privilege
     */
    $this->db->select("A.id_form");
    $this->db->join("d_privilege_form as B", "B.id_form = A.id_form");
    $this->db->where("B.id_privilege", $this->session->userdata("id_privilege"));
    $this->db->where("A.name", "aktifitas_editable");
    $cek = $this->db->get("m_form as A")->row();
//      print_r($this->session->userdata("privilege"));die;
    if($cek OR $this->session->userdata('id') == 1)
      return "nbs";
    else
      return "gagal";
    }
    function half_export_xls($id){
      $detail = $this->global_models->get("m_actifity_report", array("id_actifity_report"  =>  $id));
      $target = $this->global_models->get("d_day_actifity_report", array("id_actifity_report"  =>  $id, "tanggal" => 0));
//      print '<pre>';
//      print_r($target);die;
      $bulan = array(
          "1" =>  "Januari",
          "2" =>  "Februari",
          "3" =>  "Maret",
          "4" =>  "April",
          "5" =>  "Mei",
          "6" =>  "Juni",
          "7" =>  "Juli",
          "8" =>  "Agustus",
          "9" =>  "September",
          "10" =>  "Oktober",
          "11" =>  "Nopember",
          "12" =>  "Desember",
      );
      $outlet = $this->global_models->get_field("m_outlet", "name", array("id_outlet" => $detail[0]->id_outlet));
      $filename = "Proyeksi-".$bulan[$detail[0]->month]."-".$detail[0]->year."-Outlet {$outlet}";
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_opex AS B", "A.id_opex = B.id_opex","left");
      $opex = $this->db->get("d_opex_outlet AS A")->result();
      
      $this->db->flush_cache();
      $this->db->select("B.*");
      $this->db->where("A.id_outlet", $detail[0]->id_outlet);
      $this->db->join("m_pendapatan_lain AS B", "A.id_pendapatan_lain = B.id_pendapatan_lain","left");
      $pendapatan = $this->db->get("d_pendapatan_lain_outlet AS A")->result();
      
      $data_unit_entry = $this->global_models->get("d_day_actifity_report",array("id_actifity_report" => $id, "tanggal >" => 0, "tanggal <" => 16), "nbs", array(), "sum(service) as service, sum(service_belanja) as service_belanja, sum(belanja) as belanja, sum(p_service) as p_service, sum(p_service_plus) as p_service_plus, sum(p_belanja_plus) as p_belanja_plus, sum(p_belanja) as p_belanja, sum(total_hpp) as total_hpp");
      
      $objPHPExcel = $this->phpexcel;
      $objPHPExcel->getProperties()->setCreator("Mr Montir")
							 ->setLastModifiedBy("Mr Montir")
							 ->setTitle("Users Data")
							 ->setSubject("Users Data")
							 ->setDescription("Report users data.")
							 ->setKeywords("report users data")
							 ->setCategory("Users");

      $objPHPExcel->setActiveSheetIndex(0);
      
//      $objPHPExcel->getActiveSheet()->mergeCells('A1:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'1');
      $objPHPExcel->getActiveSheet()->setCellValue('A1', ' PROYEKSI UNIT ENTRI DAN OMSET');
      $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
      $objPHPExcel->getActiveSheet()->getStyle('A1:E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
      
      $objPHPExcel->getActiveSheet()->getStyle('A3:A5')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Outlet');
      $objPHPExcel->getActiveSheet()->setCellValue('B3', "MR MONTIR {$outlet}");
      $objPHPExcel->getActiveSheet()->mergeCells('B3:C3');
      $objPHPExcel->getActiveSheet()->getStyle("B3:C3")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Bulan');
      $objPHPExcel->getActiveSheet()->setCellValue('B4', $bulan[$detail[0]->month]." ".$detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B4:C4');
      $objPHPExcel->getActiveSheet()->getStyle("B4:C4")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Tahun');
      $objPHPExcel->getActiveSheet()->setCellValue('B5', $detail[0]->year);
      $objPHPExcel->getActiveSheet()->mergeCells('B5:C5');
      $objPHPExcel->getActiveSheet()->getStyle("B5:C5")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            ),
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Keterangan');
      $objPHPExcel->getActiveSheet()->mergeCells('A8:B8');
      $objPHPExcel->getActiveSheet()->getStyle("A8:B8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('C8', 'Target 1-15');
      $objPHPExcel->getActiveSheet()->getStyle("C8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getColumnDimension("D8")->setWidth(14);
      $objPHPExcel->getActiveSheet()->setCellValue("D8", "Perolehan 1-15");
      $objPHPExcel->getActiveSheet()->getStyle("D8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E8', 'Achievement');
      $objPHPExcel->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle("E8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('F8', 'Target');
      $objPHPExcel->getActiveSheet()->getColumnDimension("F")->setAutoSize(true);
      $objPHPExcel->getActiveSheet()->getStyle("F8")->applyFromArray(
          array(
            'alignment' => array(
              'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
              'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
            ),
            'borders' => array(
              'left'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A9', 'UNIT ENTRY');
      $objPHPExcel->getActiveSheet()->getStyle("A9:F9")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->getStyle('A9')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A10', 'Servis Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A10:B10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F10', (int)$target[0]->service);
      $format_imei = array(
        'numberformat' => array(
          'code' => '0',
        ),
      );
//      $objPHPExcel->getActiveSheet()->getStyle('F10')->applyFromArray($format_imei);
      $objPHPExcel->getActiveSheet()->getStyle('F10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F10:F10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C10', $target[0]->service/2);
      $objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C10:C10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D10', $data_unit_entry[0]->service);
      $objPHPExcel->getActiveSheet()->getStyle('D10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D10:D10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E10', '=IF(C10 > 0, D10/C10, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E10:E10")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A11', 'Servis + Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A11:B11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F11', $target[0]->service_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('F11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F11:F11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C11', $target[0]->service_belanja/2);
      $objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C11:C11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D11', $data_unit_entry[0]->service_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('D11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D11:D11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E11', '=IF(C11 > 0, D11/C11, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E11:E11")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A12', 'Belanja Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A12:B12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F12', $target[0]->belanja);
      $objPHPExcel->getActiveSheet()->getStyle("F12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F12:F12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C12', $target[0]->belanja/2);
      $objPHPExcel->getActiveSheet()->getStyle("C12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C12:C12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D12', $data_unit_entry[0]->belanja);
      $objPHPExcel->getActiveSheet()->getStyle("D12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D12:D12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E12', '=IF(C12 > 0, D12/C12, "")');
      $objPHPExcel->getActiveSheet()->getStyle("E12")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E12:E12")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A13', 'Total Unit Entry Service');
      $objPHPExcel->getActiveSheet()->getStyle("A13:B13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C13', "=C10+C11");
      $objPHPExcel->getActiveSheet()->getStyle('C13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C13:C13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D13', "=D10+D11");
      $objPHPExcel->getActiveSheet()->getStyle('D13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D13:D13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F13', "=F10+F11");
      $objPHPExcel->getActiveSheet()->getStyle('F13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F13:F13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E13', '=IF(C13 > 0, D13/C13, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E13:E13")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A14', 'Total Unit Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A14:B14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F14', "=F11+F12");
      $objPHPExcel->getActiveSheet()->getStyle('F14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F14:F14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C14', "=C11+C12");
      $objPHPExcel->getActiveSheet()->getStyle('C14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C14:C14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D14', "=D11+D12");
      $objPHPExcel->getActiveSheet()->getStyle('D14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D14:D14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E14', '=IF(C14 > 0, D14/C14, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E14')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E14:E14")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A15', 'Total Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A15:B15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F15', "=SUM(F10:F12)");
      $objPHPExcel->getActiveSheet()->getStyle('F15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F15:F15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C15', "=SUM(C10:C12)");
      $objPHPExcel->getActiveSheet()->getStyle('C15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C15:C15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D15', "=SUM(D10:D12)");
      $objPHPExcel->getActiveSheet()->getStyle('D15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D15:D15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E15', '=IF(C15 > 0, D15/C15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E15')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E15:E15")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A16', 'PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A16:F16")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('A17', 'Rata-rata Rupiah Service');
      $objPHPExcel->getActiveSheet()->getStyle("A17:B17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F17', $target[0]->rata_service);
      $objPHPExcel->getActiveSheet()->getStyle('F17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F17:F17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C17', $target[0]->rata_service);
      $objPHPExcel->getActiveSheet()->getStyle('C17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C17:C17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D17', '=IF((D10+D11) > 0, (D19+D20)/(D10+D11),"")');
      $objPHPExcel->getActiveSheet()->getStyle('D17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D17:D17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E17', '=IF(C17 > 0, D17/C17, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E17')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E17:E17")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A18', 'Rata-rata Rupiah Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A18:B18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C18', $target[0]->rata_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('C18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C18:C18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D18', '=IF((D12+D11) > 0, (D22+D21)/(D12+D11),"")');
      $objPHPExcel->getActiveSheet()->getStyle('D18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D18:D18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F18', $target[0]->rata_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('F18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F18:F18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E18', '=IF(C18 > 0, D18/C18, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E18')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E18:E18")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A13:A18')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->setCellValue('A19', 'Service Saja');
      $objPHPExcel->getActiveSheet()->getStyle("A19:B19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D19', $data_unit_entry[0]->p_service);
      $objPHPExcel->getActiveSheet()->getStyle('D19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D19:D19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('F19', "=F17*F10");
      $objPHPExcel->getActiveSheet()->getStyle('F19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F19:F19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C19', "=C17*C10");
      $objPHPExcel->getActiveSheet()->getStyle('C19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C19:C19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E19', '=IF(C19 > 0, D19/C19, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E19:E19")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A20', 'Service + Belanja');
      $objPHPExcel->getActiveSheet()->setCellValue('B20', 'Service');
      $objPHPExcel->getActiveSheet()->getStyle("A20:B20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D20', $data_unit_entry[0]->p_service_plus);
      $objPHPExcel->getActiveSheet()->getStyle('D20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D20:D20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F20', "=F17*F11");
      $objPHPExcel->getActiveSheet()->getStyle('F20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F20:F20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C20', "=C17*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C20:C20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E20', '=IF(C20 > 0, D20/C20, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E20')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E20:E20")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('B21', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A21:B21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D21', $data_unit_entry[0]->p_belanja_plus);
      $objPHPExcel->getActiveSheet()->getStyle('D21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D21:D21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F21', "=F18*F11");
      $objPHPExcel->getActiveSheet()->getStyle('F21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F21:F21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C21', "=C18*C11");
      $objPHPExcel->getActiveSheet()->getStyle('C21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C21:C21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E21', '=IF(C21 > 0, D21/C21, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E21')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E21:E21")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A22', 'Belanja');
      $objPHPExcel->getActiveSheet()->getStyle("A22:B22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D22', $data_unit_entry[0]->p_belanja);
      $objPHPExcel->getActiveSheet()->getStyle('D22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D22:D22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F22', "=F18*F12");
      $objPHPExcel->getActiveSheet()->getStyle('F22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F22:F22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C22', "=C18*C12");
      $objPHPExcel->getActiveSheet()->getStyle('C22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C22:C22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E22', '=IF(C22 > 0, D22/C22, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E22')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E22:E22")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A23', 'Total PENERIMAAN');
      $objPHPExcel->getActiveSheet()->getStyle("A23:B23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F23', "=SUM(F19:F22)");
      $objPHPExcel->getActiveSheet()->getStyle('F23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F23:F23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C23', "=SUM(C19:C22)");
      $objPHPExcel->getActiveSheet()->getStyle('C23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C23:C23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D23', "=SUM(D19:D22)");
      $objPHPExcel->getActiveSheet()->getStyle('D23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D23:D23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E23', '=IF(C23 > 0, D23/C23, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E23')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E23:E23")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A24', 'Omset per Transaksi');
      $objPHPExcel->getActiveSheet()->getStyle("A24:B24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_rp_omset = $target_rp_penerimaan/ $target_total_transaksi;
      $objPHPExcel->getActiveSheet()->setCellValue('F24', '=IF(F15 > 0, F23/F15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('F24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F24:F24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C24', '=IF(C15 > 0, C23/C15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('C24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C24:C24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D24', '=IF(D15 > 0, D23/D15, "")');
      $objPHPExcel->getActiveSheet()->getStyle('D24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D24:D24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E24', '=IF(C24 > 0, D24/C24, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E24')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E24:E24")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A24')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('A25', 'HARGA POKOK PEMBELIAN');
      $objPHPExcel->getActiveSheet()->getStyle("A25:F25")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A23:A25')->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->setCellValue('B26', '% HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A26:B26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D26', '=IF((D21+D22) > 0, D27/(D21+D22),0)');
      $objPHPExcel->getActiveSheet()->getStyle('D26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("D26:D26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F26', $target[0]->hpp/100);
      $objPHPExcel->getActiveSheet()->getStyle('F26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("F26:F26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C26', ($target[0]->hpp/100));
      $objPHPExcel->getActiveSheet()->getStyle('C26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("C26:C26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E26', '=IF(C26 > 0, D26/C26, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E26')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E26:E26")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A27', 'Total HPP');
      $objPHPExcel->getActiveSheet()->getStyle("A27:B27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
//      $target_total_hpp = $target[0]->hpp * ($target_rp_belanja + $target_rp_belanja_p) / 100;
      $objPHPExcel->getActiveSheet()->setCellValue('F27', "=F26*(F22+F21)");
      $objPHPExcel->getActiveSheet()->getStyle('F27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F27:F27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C27', "=C26*(C22+C21)");
      $objPHPExcel->getActiveSheet()->getStyle('C27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C27:C27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D27', $data_unit_entry[0]->total_hpp);
      $objPHPExcel->getActiveSheet()->getStyle('D27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D27:D27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E27', '=IF(C27 > 0, D27/C27, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E27')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E27:E27")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A28', 'GROSS MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A28:B28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F28', "=F23-F27");
      $objPHPExcel->getActiveSheet()->getStyle('F28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F28:F28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C28', "=C23-C27");
      $objPHPExcel->getActiveSheet()->getStyle('C28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C28:C28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D28', "=D23-D27");
      $objPHPExcel->getActiveSheet()->getStyle('D28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D28:D28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E28', '=IF(C28 > 0, D28/C28, "")');
      $objPHPExcel->getActiveSheet()->getStyle('E28')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E28:E28")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A29', 'OPERATIONAL EXPENSE (OPEX)');
      $objPHPExcel->getActiveSheet()->getStyle("A29:F29")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->getStyle('A27:A29')->getFont()->setBold(true);
      
      if(is_array($opex)){
        $no = 1;
        $target_opex_total = "=SUM(F".(29+$no);
        $target_opex_total_c = "=SUM(C".(29+$no);
        $str_col = ord("F");
        $cell_awal = (29+1);
        foreach($opex as $op){
          $data_opex = $this->global_models->get("d_day_actifity_opex",array("id_actifity_report" => $id, "tanggal >" => 0, "tanggal <" => 16, "id_opex" => $op->id_opex), "nbs", array(), "sum(qty) as qty");
          
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_opex = $this->global_models->get_field("d_day_actifity_opex", "qty", array("id_actifity_report" => $id, "id_opex" => $op->id_opex, "tanggal" => 0));
          if($target_opex === FALSE)
            $target_opex = "";
          $objPHPExcel->getActiveSheet()->setCellValue('F'.(29+$no), $target_opex);
          $objPHPExcel->getActiveSheet()->getStyle('F'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("F".(29+$no).":F".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('D'.(29+$no), $data_opex[0]->qty);
          $objPHPExcel->getActiveSheet()->getStyle('D'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("D".(29+$no).":D".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex/2);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('E'.(29+$no), '=IF(C'.(29+$no).' > 0, D'.(29+$no).'/C'.(29+$no).', "")');
          $objPHPExcel->getActiveSheet()->getStyle('E'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
          $objPHPExcel->getActiveSheet()->getStyle("E".(29+$no).":E".(29+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );
          
          $no++;
        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(29+$no), 'Total Opex');
      $objPHPExcel->getActiveSheet()->getStyle("A".(29+$no).":B".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print $target_opex_total.":C".(29+$no).")";die;
      $objPHPExcel->getActiveSheet()->setCellValue('F'.(29+$no), $target_opex_total.":F".(28+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('F'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F".(29+$no).":F".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(29+$no), $target_opex_total_c.":C".(28+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(29+$no).":C".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(29+$no), "=SUM(D".$cell_awal.":D".(28+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('D'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D".(29+$no).":D".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(29+$no), '=IF(C'.(29+$no).' > 0, D'.(29+$no).'/C'.(29+$no).', "")');
      $objPHPExcel->getActiveSheet()->getStyle('E'.(29+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E".(29+$no).":E".(29+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(30+$no), 'MARGIN');
      $objPHPExcel->getActiveSheet()->getStyle("A".(30+$no).":B".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $kl = 'F'.(30+$no);
      $kl_c = 'C'.(30+$no);
      $ganti_kl = (30+$no);
      $objPHPExcel->getActiveSheet()->setCellValue('F'.(30+$no), "=F28-F".(29+$no));
      $objPHPExcel->getActiveSheet()->getStyle('F'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F".(30+$no).":F".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(30+$no), "=C28-C".(29+$no));
      $objPHPExcel->getActiveSheet()->getStyle('C'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(30+$no).":C".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(30+$no), "=D28-D".(29+$no));
      $objPHPExcel->getActiveSheet()->getStyle('D'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D".(30+$no).":D".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(30+$no), '=IF(C'.(30+$no).' > 0, D'.(30+$no).'/C'.(30+$no).', "")');
      $objPHPExcel->getActiveSheet()->getStyle('E'.(30+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E".(30+$no).":E".(30+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
//      print_r($opex);die;
      
      $objPHPExcel->getActiveSheet()->getStyle('A'.(29+$no).':A'.(30+$no))->getFont()->setBold(true);
      $no = 30+$no;
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(1+$no), 'PENDAPATAN LAIN-LAIN');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(1+$no))->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getStyle("A".(1+$no).":F".(1+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'top'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      if(is_array($pendapatan)){
        $target_pendapatan_total = "=SUM(F".(2+$no);
        $target_pendapatan_total_c = "=SUM(C".(2+$no);
        $str_col = ord("F");
        $cell_awal_row = ($no+2);
        foreach($pendapatan as $op){
          $data_pendapatan = $this->global_models->get("d_day_actifity_pendapatan_lain",array("id_actifity_report" => $id, "tanggal >" => 0, "tanggal <" => 16, "id_pendapatan_lain" => $op->id_pendapatan_lain), "nbs", array(), "sum(qty) as qty");
          
          $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), $op->name);
          $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $target_pendapatan = $this->global_models->get_field("d_day_actifity_pendapatan_lain", "qty", array("id_actifity_report" => $id, "id_pendapatan_lain" => $op->id_pendapatan_lain, "tanggal" => 0));
          if($target_pendapatan === FALSE)
            $target_pendapatan = "";
          $objPHPExcel->getActiveSheet()->setCellValue('F'.(2+$no), $target_pendapatan);
          $objPHPExcel->getActiveSheet()->getStyle('F'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("F".(2+$no).":F".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_DOUBLE
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('D'.(2+$no), $data_pendapatan[0]->qty);
          $objPHPExcel->getActiveSheet()->getStyle('D'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("D".(2+$no).":D".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan/2);
          $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
          $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $objPHPExcel->getActiveSheet()->setCellValue('E'.(2+$no), '=IF(C'.(2+$no).' > 0, D'.(2+$no).'/C'.(2+$no).', "")');
          $objPHPExcel->getActiveSheet()->getStyle('E'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
          $objPHPExcel->getActiveSheet()->getStyle("E".(2+$no).":E".(2+$no))->applyFromArray(
              array(
                'borders' => array(
                  'bottom'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                  'right'     => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN
                  ),
                ),
              )
          );
          
          $no++;
        }
      }
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(2+$no), 'Total Pendapatan Lain');
      $objPHPExcel->getActiveSheet()->getStyle("A".(2+$no).":B".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('F'.(2+$no), $target_pendapatan_total.":F".(1+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('F'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F".(2+$no).":F".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$no), $target_pendapatan_total_c.":C".(1+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(2+$no).":C".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(2+$no), "=SUM(D".$cell_awal_row.":D".(1+$no).")");
      $objPHPExcel->getActiveSheet()->getStyle('D'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D".(2+$no).":D".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(2+$no), '=IF(C'.(2+$no).' > 0, D'.(2+$no).'/C'.(2+$no).', "")');
      $objPHPExcel->getActiveSheet()->getStyle('E'.(2+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E".(2+$no).":E".(2+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A'.(3+$no), 'LABA/RUGI');
      $objPHPExcel->getActiveSheet()->getStyle("A".(3+$no).":B".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('A7', '* Tekan F2 lalu Enter untuk format angka exponential');
      $objPHPExcel->getActiveSheet()->getStyle('A7')->getFont()->setItalic(true);
      $objPHPExcel->getActiveSheet()->getStyle("A7")->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
//      $target_laba = $target_pendapatan_total + $target_margin;
//      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+9");
      $objPHPExcel->getActiveSheet()->setCellValue('F'.(3+$no), "=F".(2+$no)."+".$kl);
      $objPHPExcel->getActiveSheet()->getStyle('F'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("F".(3+$no).":F".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('C'.(3+$no), "=C".(2+$no)."+".$kl_c);
      $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("C".(3+$no).":C".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('D'.(3+$no), "=D".(2+$no)."+D".$ganti_kl);
      $objPHPExcel->getActiveSheet()->getStyle('D'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
      $objPHPExcel->getActiveSheet()->getStyle("D".(3+$no).":D".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->setCellValue('E'.(3+$no), '=IF(C'.(3+$no).' > 0, D'.(3+$no).'/C'.(3+$no).', "")');
      $objPHPExcel->getActiveSheet()->getStyle('E'.(3+$no))->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
      $objPHPExcel->getActiveSheet()->getStyle("E".(3+$no).":E".(3+$no))->applyFromArray(
          array(
            'borders' => array(
              'bottom'     => array(
                'style' => PHPExcel_Style_Border::BORDER_DOUBLE
              ),
              'right'     => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
              ),
            ),
          )
      );
      
      $objPHPExcel->getActiveSheet()->freezePane('C9');
      $objPHPExcel->getActiveSheet()->getStyle('A'.(2+$no).':A'.(3+$no))->getFont()->setBold(true);
      
      $objPHPExcel->getActiveSheet()->getStyle('A8:'.$this->int_to_string(65+5+$detail[0]->day_in_month).'8')->getFont()->setBold(true);
      $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(17);
      $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
      $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(14);
      $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(18);
      $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(18);
      $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(18);
      
      $objPHPExcel->setActiveSheetIndex(0);
      header('Content-Type: application/vnd.ms-excel');
      header('Content-Disposition: attachment;filename="'.$filename."-".date("Y m d").'"');
      header('Cache-Control: max-age=0');
      $objWriter = PHPExcel_IOFactory::createWriter($this->phpexcel, 'Excel5');
//$objWriter->save(str_replace('.php', '.xls', __FILE__));
      $objWriter->save('php://output');die;
    }
}
?>
